
************************************************
*** Table on provisions and ETRs	     ***
************************************************

*Read
u "$cur_sample" if inlist(year,2016,2019), clear
do $cleaning/renameSOI

*Keep ETR firms 	
keep if pidom_soi>0

*Set panel 
gegen t = group(year)
tsset firmid t

*ETR 
g etr = uscetr_soi*100 
g letr = ln(1 + etr)
g detr = d.etr
g dletr = d.letr

*Keep only 2016 + the ETR change 
foreach i in detr dletr {
	gegen x = max(`i'), by(firmid)
	replace `i' = x 
	drop x
}
keep if year==2016

*MTR brackets
g brk0 = taxable_income==0
g brk1 = taxable_income>0 & taxable_income<5e4
g brk2 = taxable_income>=5e4 & taxable_income<7.5e4
g brk3 = taxable_income>=7.5e4 & taxable_income<10e4
g brk4 = taxable_income>=1e5 & taxable_income<3.35e5
g brk5 = taxable_income>=.335e6 & taxable_income<10e6
g brk6 = taxable_income>=10e6 & taxable_income<15e6
g brk7 = taxable_income>=15e6 & taxable_income<18e6
g brk8 = taxable_income>=18e6 & !mi(taxable_income)
g bracket = 0 if brk0 
forval i = 1/8 {
	replace bracket = `i' if brk`i'
} 

*Low vs. High MTR brackets 
g brlo = bracket<=2
g brhi = bracket>=4
g brmi = !brlo & !brhi & !mi(taxable_income)
label var brlo "<=2nd MTR Bracket"
label var brhi ">=4th MTR Bracket"
*AMT 
g amt = alternative_minimum_tax>0 & !mi(alternative_minimum_tax)
label var amt "AMT"

*NOL 
g nol_able = nol_carryforward_available>0 & !mi(nol_carryforward_available)
label var nol_able "NOL"

*Expensing 
cap drop bonus
g bonus = (inv)>0 & !mi(inv)
label var bonus "Bonus (Inv>0)"

*DPAD 
g dpad = dpad_amt>0 & !mi(dpad_amt)
label var dpad "DPAD"

*Interest limitation
g net_intrst = max(0,interest_paid - interest_received)
g intlim = net_intrst>.3*(ebitda) & taxable_income>0
label var intlim "Interest Limitation"

*Foreign provisions
label var mne "Multinational"

*Reconstruct a couple variables
g etr_post = etr+detr
g payroll = cost_of_labor + salaries_wages_nde + compensation_officers 
*Winsorize ETR change 
winsor2 detr, cuts(5 95) replace
winsor2 etr, cuts(0 95) replace
winsor2 etr_post, cuts(0 95) replace

*Regress ETR change on 2016 characteristics
global X16 brlo brhi amt nol_able bonus dpad intlim mne 

*Multivariate regression, all firms
eststo clear
eststo priv: reghdfe detr $X16 [pw=weightSOI] if firmtype_alt>2, cluster(firmid) noab
estadd local fe "No"
estadd local w "No"
local Nall = string(e(N),"%9.0fc")
local ref = string(_b[_cons],"%9.2f")
local refse = string(_se[_cons],"%9.2f")
predict etrhat 

*Coefficient plot
coefplot priv, keep(${X16}) levels(95)  ///
	text(.4 -14 "{bf: 2016 Firm Characteristic}", size(small)) ///
	xtitle("PP change in ETR, 2016-2019") ///
	note("N = `Nall' SOI firms" "Constant: `ref', se=`refse'", pos(6) size(small))
graph export "$results/provisions_private.pdf", replace

eststo priv_fe: reghdfe detr $X16 [pw=weightSOI] if firmtype_alt>2, cluster(firmid) a(naics2)
estadd local fe "Yes"
estadd local w  "SOI"

esttab priv priv_fe using "$results/provisions_private_fe.tex",  ///
	label se(%9.3f) b(%9.3f) ///
	stats(fe r2 N, ///
	label("Industry FE" "R2" "N Firms") ///
	fmt(%9.0f %9.2f %9.2fc %9.0fc)) nogaps compress ///
	mtitle("$ \Delta $ ETR" "$ \Delta $ ETR" "$ \Delta $ ETR" "$ \Delta $ ETR" ) ///
	substitute(\_ _) star(** 0.05 *** 0.01) nonotes replace
